package com.mvvm.library.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.mvvm.library.app.XMvvm;

/**
 * @创建时间：2022/7/8
 * @作者：小蔡
 * @功能介绍：数据储存
 */
public class SharedPrefUtil {
    public static String TOKEN = "TOKEN";
    private static SharedPreferences mSp;

    private static SharedPreferences getSharedPref(Context context) {
        if (mSp == null) {
            mSp = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        }
        return mSp;
    }


    public static void putBoolean(String key, boolean value) {
        getSharedPref(XMvvm.getInstance()).edit().putBoolean(key, value).commit();
    }

    public static boolean getBoolean(String key, boolean defValue) {
        return getSharedPref(XMvvm.getInstance()).getBoolean(key, defValue);
    }

    public static void putString(String key, String value) {
        getSharedPref(XMvvm.getInstance()).edit().putString(key, value).commit();
    }

    public static String getString(String key) {
        return getSharedPref(XMvvm.getInstance()).getString(key, "");
    }

    public static void removeString(String key) {
        getSharedPref(XMvvm.getInstance()).edit().remove(key).commit();
    }

    public static void putInt(String key, int value) {
        getSharedPref(XMvvm.getInstance()).edit().putInt(key, value).commit();
    }

    public static int getInt(String key, int defValue) {
        return getSharedPref(XMvvm.getInstance()).getInt(key, defValue);
    }

}